package com.zhanghe.study.study_scala.fun

/**
 * 异常
 * @author zh
 * @date 2021/5/1 11:07
 */
object TestException {
  def main(args: Array[String]): Unit = {
    try {
      var a = 10 / 0
    } catch {
      // case可以匹配异常进行处理
      // => 后为匹配后所执行的操作
      case e: ArithmeticException => println("操作出错了" + e.getMessage)
      case e: Exception => {
        println("出现了不知道的异常")
      }
    } finally {
      println("不管报没报错，总得干点啥")
    }

    myFun()
  }

  @throws(classOf[ArithmeticException])
  def myFun() = {
    var a = 10 / 0

  }

  def test() : Nothing = {
    throw new UnsupportedOperationException("非法操作")
  }

}
